/*
 * Copyright 2009 Tran Nhut Trung.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 */
package com.gdevelop.gwtxp.gen;

import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.DecoratedTabPanel;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.DisclosurePanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.HorizontalSplitPanel;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.user.client.ui.MenuItemSeparator;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.SuggestBox;
import com.google.gwt.user.client.ui.SuggestOracle;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Tree;
import com.google.gwt.user.client.ui.TreeItem;
import com.google.gwt.user.client.ui.UIObject;
import com.google.gwt.user.client.ui.VerticalPanel;

import com.google.gwt.user.client.ui.VerticalSplitPanel;

import java.util.Collection;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import org.eclipse.core.databinding.validation.IValidator;

public class UIModels {
  public static class ATTRIBUTE implements Comparable<ATTRIBUTE>{
    public String name = "";
    public Class type;
    public String typeName = "";
    public String doc = "";
    
    public ATTRIBUTE(String name, Class type){
      this.name = name;
      this.type = type;
    }
    public ATTRIBUTE(String name, Class type, String typeName, String doc){
      this.name = name;
      this.type = type;
      this.typeName = typeName;
      this.doc = doc;
    }

    public String getName(){
      return name;
    }
    public String getTypeName(){
      return typeName;
    }
    public String getDoc(){
      return doc;
    }

    public int compareTo(ATTRIBUTE o) {
      return name.compareTo(o.name);
    }
  }
  
  public static final Class[] MODEL_CLASSES = new Class[]{
    Button.class
    , CheckBox.class
    , RadioButton.class
    , Label.class
    , HTML.class
    , Hyperlink.class
    , TextBox.class
    , PasswordTextBox.class
    , TextArea.class
    , ListBox.class
    , Image.class
    , SuggestBox.class
    
    // Panels
    , SimplePanel.class
    , FlowPanel.class
    , HorizontalPanel.class
    , VerticalPanel.class
    , FlexTable.class
    , Grid.class
    , DecoratorPanel.class
    , AbsolutePanel.class
    , DisclosurePanel.class
    , HorizontalSplitPanel.class
    , VerticalSplitPanel.class
    , DecoratedTabPanel.class
    , ScrollPanel.class
    , TabPanel.class
    , Tree.class
    , TreeItem.class
    
    , MenuBar.class
    , MenuItem.class
    , MenuItemSeparator.class
    
    // pseudo widget
    , Tab.class
    , Errors.class
    , DataTable.class
    , TableCell.class
    , HeaderCell.class
  };
  
  public static final Map<Class, List<ATTRIBUTE>> ADDITIONAL_ATTRS = new Hashtable<Class, List<ATTRIBUTE>>();
  static{
    Vector<ATTRIBUTE> attrs;
    
    attrs = new Vector<ATTRIBUTE>();
    attrs.add(new ATTRIBUTE("j_name", String.class, "String", "Java variable name, used to get the UI object by its name"));
    attrs.add(new ATTRIBUTE("addStyleNames", String.class, "String", "Additional style names separated by comma"));
    attrs.add(new ATTRIBUTE("addStyleDependentNames", String.class, "String", "Additional dependent style names separated by comma"));
    ADDITIONAL_ATTRS.put(UIObject.class, attrs);
    
    attrs = new Vector<ATTRIBUTE>();
    attrs.add(new ATTRIBUTE("rows", int.class, "int", "Number of rows in this grid. This is required attribute."));
    attrs.add(new ATTRIBUTE("columns", int.class, "int", "Number of columns in this grid. This is required attribute."));
    ADDITIONAL_ATTRS.put(Grid.class, attrs);

    attrs = new Vector<ATTRIBUTE>();
    attrs.add(new ATTRIBUTE("values", Collection.class, "Collection", "Collection of values to in this ListBox"));
    ADDITIONAL_ATTRS.put(ListBox.class, attrs);
    
    attrs = new Vector<ATTRIBUTE>();
    attrs.add(new ATTRIBUTE("headerText", String.class, "String", "Text displayed in header of this DisclosurePanel"));
    ADDITIONAL_ATTRS.put(DisclosurePanel.class, attrs);
    
    attrs = new Vector<ATTRIBUTE>();
    attrs.add(new ATTRIBUTE("vertical", boolean.class, "boolean", "Whether this MenuBar is vertical or horizontal."));
    ADDITIONAL_ATTRS.put(MenuBar.class, attrs);
    
    attrs = new Vector<ATTRIBUTE>();
    attrs.add(new ATTRIBUTE("suggestOracle", SuggestOracle.class, "SuggestOracle", "The SuggestOracle of this SuggestBox"));
    ADDITIONAL_ATTRS.put(SuggestBox.class, attrs);
    
    attrs = new Vector<ATTRIBUTE>();
    attrs.add(new ATTRIBUTE("validator", IValidator.class, "IValidator", "The validator to validate user input."));
    attrs.add(new ATTRIBUTE("pattern", String.class, "String", "Pattern used in conversion between numeric/date and String"));
    ADDITIONAL_ATTRS.put(TextBox.class, attrs);

    attrs = new Vector<ATTRIBUTE>();
    attrs.add(new ATTRIBUTE("pattern", String.class, "String", "Pattern used to format numeric/date"));
    ADDITIONAL_ATTRS.put(Label.class, attrs);


    // TODO: validator for other widget
  }
}
